<template>
  <div class="">
    <div class="container">
      <div class="tasks">
        <div class="title-box">
          <h3>正在进行</h3>
          <span class="run-count">{{runList.length}}</span>
        </div>
        <ul class="running-tasks-box">
          <li class="list-item" v-for="(item, index) in runList" :key="index">
            <div>
              <input type="checkbox" v-model="item.flag" />
               <input type="text" v-if="item.eit" v-model="item.msg" @change="item.eit = false">
              <span v-else @dblclick="item.eit = true">{{ item.msg }}</span>
            </div>
            <div class="del" @click="del(item.id)">-</div>
          </li>
        </ul>
      </div>
      <div class="tasks">
        <div class="title-box">
          <h3>已经完成</h3>
          <span class="finish-count">{{finishList.length}}</span>
        </div>
        <ul class="finish-task-box">
          <li
            class="list-item"
            v-for="(item, index) in finishList"
            :key="index"
          >
            <div>
              <input type="checkbox" v-model="item.flag" />
              <input type="text" v-if="item.eit" v-model="item.msg" @change="item.eit = false">
              <span v-else @dblclick="item.eit = true">{{item.msg }}</span>
            </div>
            <div class="del" @click="del(item.id)">-</div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    dataList: Array,
  },
  watch: {
    dataList: {
      handler() {
        // 从所有的数据里面过滤出 正在进行的数据和已完成的数据
        // console.log(1);
        localStorage.setItem('list',JSON.stringify(this.dataList));
        this.$nextTick(() => {
            // console.log(2);
        //   let arr = [1,2,3,4,5];
        //   let arr1 = [];
        //   arr1 = arr.filter(item => item>3);
        //   console.log(arr1);
          console.log(this.dataList);
          // filter 过滤数组返回符合条件的新数组
          this.runList = this.dataList.filter((item) => !item.flag);
          this.finishList = this.dataList.filter((item) => item.flag);
        });
        // console.log(1);
        // setTimeout(()=>{
        //     console.log(2);
        // },0)
        // console.log(3);
      },
      deep: true, // 开启深度监听
      immediate: true // 初始化数据的时候就监听，
    },
  },
  data() {
    return {
      runList: [], // 正在进行的数据
      finishList: [], // 已经完成的数据
    };
  },
  mounted() {},
  methods: {
    del(id){  // 这里是不能操作 dataList 父向子传值是一个单项数据流
      this.$emit('del',id);
    },


    // dbInp(val,bool){
    //  this.$emit('eit',{id:val,boolVal:bool});
    // }
    // showInp(val){ // 双击修改的事件
    // // console.log('fghjkl');
    //   this.$emit('eit',val);
    // },


    // hideInp(val){ // 隐藏input触发的事件
    //   this.$emit('hideEit',val);
    // }
  },
};
</script>

<style lang='scss' scoped>
.container {
  width: 100%;
}
.tasks {
  width: 600px;
  margin: 0 auto;
  margin-top: 50px;
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.title-box {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h3 {
  font-size: 26px;
  font-weight: bold;
}

.title-box span {
  width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  background-color: #fff;
  border-radius: 20px;
}

.list-item {
  width: 100%;
  height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #fff;
  border-left: 4px solid #629a9c;
  border-radius: 6px;
  padding-left: 10px;
  padding-right: 15px;
  margin-bottom: 20px;
}

.list-item input[type=checkbox] {
  height: 30px;
  width: 30px;
  vertical-align: middle;
}

.list-item span {
  display: inline-block;
  vertical-align: middle;
}

.del {
  box-sizing: content-box;
  display: inline-block;
  width: 14px;
  height: 12px;
  border-radius: 14px;
  border: 6px double #fff;
  background: #ccc;
  line-height: 14px;
  text-align: center;
  color: #fff;
  font-weight: bold;
  font-size: 14px;
  cursor: pointer;
}

.finish-task-box {
  opacity: 0.5;
}
</style>
